package cn.tedu.boot62.mapper;

import cn.tedu.boot62.entity.User;
import cn.tedu.boot62.entity.Weibo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface WeiboMapper {
    //数据库中timestamp字段为时间字段, 赋值null会设置为当前系统时间
    //#{}是从对象中获取属性值的方式, 里面写的是属性名 不是字段名
    @Insert("insert into weibo values(null,#{content},#{author}," +
            "#{url},null,#{userId})")
    void insert(Weibo weibo);

    @Select("select id,content,url,author from weibo order by created desc")
    List<Weibo> select();

    @Select("select id,content,created from weibo where user_id=#{id}")
    List<Weibo> selectMyWeibo(User user);

    @Delete("delete from weibo where id=#{id}")
    void delete(int id);
}
